<template>
  <div>
    <div style="text-align: center; ">
      <el-button
        icon="el-icon-folder-delete"
        size="mini"
        @click="clearSign"
        v-if="showButton.cancelIssue"
      >撤销签发</el-button>
      <el-button
        icon="el-icon-paperclip"
        size="mini"
        @click="openAddFile"
        v-if="showButton.fileUpload"
      >上传附件</el-button>
      <el-button
        icon="el-icon-reading"
        size="mini"
        @click="openAddReview"
        v-if="showButton.review"
      >检阅单据</el-button>
      <el-button
        icon="el-icon-upload2"
        size="mini"
        @click="openSubmit"
        v-if="showButton.submit"
      >单据提交</el-button>
      <el-button
        icon="el-icon-edit-outline"
        size="mini"
        @click="openAddSign"
        v-if="showButton.issue"
      >单据签发</el-button>
      <el-button
        icon="el-icon-download"
        size="mini"
        @click="exportFile"
        v-if="showButton.export"
      >单据导出</el-button>
    </div>
    <add-files ref="addFileDig"></add-files>
    <add-review ref="addReviewDig" :child-data="bussId"></add-review>
    <add-sign ref="addSignDig" :child-data="bussId" child-type="sign"></add-sign>
    <add-sign ref="addSubmitDig" :child-data="bussId" child-type="submit"></add-sign>
  </div>
</template>

<script>
import AddFiles from '@/components/SpsPublic/FileList/AddFiles'
import AddReview from '@/components/SpsPublic/ReviewList/AddReview'
import AddSign from '@/components/SpsPublic/SignList/AddSign'
import store from '@/store/index'
import { getFunNo } from '@/utils/party'

export default {
  name: 'spsMasterFoot',
  components: { AddSign, AddReview, AddFiles },
  props: ['childData'],
  data() {
    return {
      store: store,

      bussId: null,
      funNo: null,
      isEnd: false,

      // 按钮显示判断
      showButton: {
        // 撤销签发
        cancelIssue: false,
        // 附件上传
        fileUpload: false,
        // 检阅单据
        review: false,
        // 单据提交
        submit: false,
        // 单据签发
        issue: false,
        // 单据导出
        export: true,
      },
      singleStore: null,
    }
  },
  methods: {
    refresh(row) {
      this.bussId = row.selectedCt.ct_id
      this.isEnd = row.selectedCt.ct_end_name == '已签发'
      this.handleType = row.selectedCt.handleType
      this.funNo = row.ctFunNo
      this.singleStore = store.getters.singleStore['main' + this.funNo]
      const myStore = this.singleStore
      if (
        myStore &&
        myStore.handleType &&
        myStore.ifEnd != undefined &&
        myStore.ifStep
      ) {
        // 走流程的编辑操作,单据已签发的才可撤销签发
        this.showButton.cancelIssue =
          myStore.handleType == 'edit' && myStore.ifEnd && myStore.ifStep == '1'
        this.showButton.fileUpload = !myStore.ifEnd && myStore.ifStep == '1'
        this.showButton.review =
          myStore.handleType == 'edit' && myStore.ifEnd && myStore.ifStep == '1'
        this.showButton.submit = !myStore.ifEnd && myStore.ifStep == '1'
        this.showButton.issue = !myStore.ifEnd && myStore.ifStep == '1'
      }
    },
    openAddFile() {
      this.$refs['addFileDig'].handleOpenDialog()
    },
    openAddReview() {
      this.$refs['addReviewDig'].handleOpenDialog()
    },
    openAddSign() {
      this.$refs['addSignDig'].handleOpenDialog()
    },
    openSubmit() {
      this.$refs['addSubmitDig'].handleOpenDialog()
    },
    exportFile() {
      this.$confirm('下载当前业务单据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'info',
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '下载成功!',
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '取消了操作',
          })
        })
    },
    clearSign() {
      this.$confirm(
        '该业务已经签发，是否撤销？ 注意，撤销后，单据若属于KPI考核体系，则所获积分会自动撤销',
        '请确认',
        {
          distinguishCancelAndClose: true,
          confirmButtonText: '确认',
          cancelButtonText: '取消',
        }
      )
        .then(() => {
          this.$message({
            type: 'info',
            message: '业务已撤销，系统自动会去刷新',
          })
        })
        .catch((action) => {
          // this.$message({
          //   type: 'info',
          //   message:
          //     action === 'cancel'
          //       ? '我挥挥手，不带走一片云彩'
          //       : '什么?廊桥遗梦',
          // })
        })
    },
  },
}
</script>

<style scoped>
</style>
